Skip to content

[transport] usb: Fix htool crash on USB disconnect#249

Open
wak-google wants to merge 1 commit intogoogle:mainfrom
wak-google:libusb-transport
Open

[transport] usb: Fix htool crash on USB disconnect#249
wak-google wants to merge 1 commit intogoogle:mainfrom
wak-google:libusb-transport

Conversation

@wak-google
Copy link
Copy Markdown
Collaborator

Previously, libhoth_usb_fifo_run_transfers() could return while one or more libusb transfers were still pending. This happened if the second transfer submission failed, or if the event handling loop was interrupted by a signal (e.g. SIGINT).

When htool subsequently attempted to close and reopen the transport, it would call libusb_free_transfer() on these pending transfers, triggering an assertion failure in libusb:
'usbi_mutex_lock: Assertion pthread_mutex_lock(mutex) == 0 failed'

This change ensures that:

  1. All submitted transfers are completed (success, error, or cancel) before the function returns.
  2. If a transfer submission fails, any other successfully submitted transfer is cancelled and waited for.
  3. Signal interruptions do not cause an early return while transfers are pending.
  4. Completion flags are correctly initialized on open.

Verified on yutulis-ru4-bmc-01 with 1000 iterations of target reset spam without a crash.

Previously, libhoth_usb_fifo_run_transfers() could return while one
or more libusb transfers were still pending. This happened if the
second transfer submission failed, or if the event handling loop was
interrupted by a signal (e.g. SIGINT).

When htool subsequently attempted to close and reopen the transport,
it would call libusb_free_transfer() on these pending transfers,
triggering an assertion failure in libusb:
'usbi_mutex_lock: Assertion pthread_mutex_lock(mutex) == 0 failed'

This change ensures that:
1. All submitted transfers are completed (success, error, or cancel)
   before the function returns.
2. If a transfer submission fails, any other successfully submitted
   transfer is cancelled and waited for.
3. Signal interruptions do not cause an early return while transfers
   are pending.
4. Completion flags are correctly initialized on open.

Verified on yutulis-ru4-bmc-01 with 1000 iterations of target reset
spam without a crash.

Signed-off-by: William A. Kennington III <wak@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant